package API.SystemDome;

/**
 * ClassName:SystemText005
 * Package:API.SystemDome
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/1/30-22:12
 * @Version:v1.0
 */
public class SystemText005 {
    public static void main(String[] args) {
        //如果数据源数组和目的地数组都是引用数据型,那么子类类型可以可以给父类类型
        Student s1 = new Student("zhangsan", 23);
        Student s2 = new Student("lisi", 23);
        Student s3 = new Student("wangwu", 23);

        Student[] arr1 = {s1, s2, s3};
//        Student[]arr2 = new Student[3];
        Person[] arr2 = new Student[3];


        System.arraycopy(arr1, 0, arr2, 0, 3);
        for (int i = 0; i < arr2.length; i++) {
//            Student stu = arr2[i];
            Student stu = (Student) arr2[i];
            System.out.println(stu.getName() + " " + stu.getAge());
        }
    }
}

class Person {
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

class Student extends Person {
    public Student() {
    }

    public Student(String name, int age) {
        super(name, age);
    }
}